{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "using NamedColors\n",
    "using Colors\n",
    "using ColorTypes\n",
    "using StatsBase\n",
    "using Learn\n",
    "using MLDataUtils\n",
    "using Iterators\n",
    "using MultivariateStats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "const allowed_chars = Set(['a':'z'; '\\''; ' '; '/'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "mega_dict = merge(#load_crayola(),\n",
    "                  #    load_resene(),\n",
    "                      load_nbs(),\n",
    "                      load_xkcd(),\n",
    "                      load_x11())\n",
    "test_training_dict=similar(mega_dict)\n",
    "for (kk, vv) in mega_dict\n",
    "    name = lowercase(kk)\n",
    "    length(setdiff( Set(name), allowed_chars)) > 0  && continue\n",
    "    test_training_dict[name] = vv\n",
    "end\n",
    "test_training_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "function encode_output(raw::Colorant)\n",
    "    #Encoding Angles: http://stats.stackexchange.com/a/218547/36769\n",
    "    hsv = convert(HSV, raw)\n",
    "    [(sind(hsv.h)+1)/2, (cosd(hsv.h)+1)/2, hsv.s, hsv.v]\n",
    "end\n",
    "\n",
    "function decode_output(out)\n",
    "    hue = rad2deg(atan2(2out[1]-1, 2out[2]-1))\n",
    "    sat = out[3]\n",
    "    val = out[4]\n",
    "    HSV(hue, sat, val)\n",
    "end\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "const nchars = 26+2\n",
    "function char2index(c::Char)::Int\n",
    "    if c ∈ 'a':'z'\n",
    "        c-'a'\n",
    "    elseif c==' '\n",
    "        'z'+1\n",
    "    elseif c=='/'\n",
    "        'z'+2\n",
    "    elseif c=='\\''\n",
    "        'z'+3\n",
    "    else\n",
    "        error(\"$c is out of range\")\n",
    "    end\n",
    "end\n",
    "\n",
    "\"\"\"\n",
    "Builds a ngram_encoder, out of a alphabet encoder\n",
    "`n` the length of the ngrams\n",
    "`m` the length of the alphabet\n",
    "`alpha_encoder` must map the alphabet to the range 0:alphasize-1\n",
    "\"\"\"\n",
    "function ngram_encoder(alpha_encoder, alphasize)\n",
    "    function ngram_encoder_inner(alphastring)\n",
    "        n=length(alphastring)\n",
    "        n_ngrams = alphasize^n-1\n",
    "        alphasize.^(0:n-1)⋅alpha_encoder.(collect(alphastring))\n",
    "    end\n",
    "end\n",
    "\n",
    "function encode_input(name::AbstractString; n=1)\n",
    "    alphasize = 26+3\n",
    "    coder = ngram_encoder(char2index, alphasize)\n",
    "    \n",
    "    ngrams = partition(name, n, 1) |> collect\n",
    "    name_inds::Vector{Int} = coder.(ngrams)\n",
    "    counts(name_inds, alphasize^n)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Method definition get_data(Any) in module Main at In[6]:3 overwritten at In[25]:3.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "get_data (generic function with 1 method)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function get_data(data_dict)\n",
    "\n",
    "    colors = collect(values(data_dict))\n",
    "    ys = hcat(encode_output.(colors)...)\n",
    "    \n",
    "    names = collect(keys(data_dict))\n",
    "    xs = hcat(encode_input.(names)...).*1.0\n",
    "\n",
    "    #These could all be views, but PCA don't like that\n",
    "    x_train = xs[:, 1:9*end÷10]\n",
    "    y_train = ys[:, 1:9*end÷10]\n",
    "    x_test = xs[:,1+9*end÷10 : end]\n",
    "    y_test = ys[:,1+9*end÷10 : end]\n",
    "    \n",
    "    (x_train, y_train), (x_test, y_test)\n",
    "end\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "full_encode_input (generic function with 2 methods)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function full_encode_input(M, name::AbstractString)\n",
    "    x=encode_input(name)*1.0\n",
    "    MultivariateStats.transform(M,x)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((\n",
       "[1.45161 -0.152558 … 0.806574 -1.3548; 0.373618 -0.548537 … -0.429015 0.0241556; … ; -0.231092 0.191179 … 1.32662 -0.068711; 0.778269 0.0438234 … 0.250988 -0.871217],\n",
       "\n",
       "Float32[0.994721 0.350743 … 0.618108 0.204548; 0.427534 0.977203 … 0.98585 0.0966291; 0.929032 0.892019 … 0.396078 0.857708; 0.607843 0.835294 … 1.0 0.992157]),(\n",
       "[-0.917094 -0.828917 … 0.448083 1.17184; 0.759519 0.367389 … 0.76142 0.136729; … ; 0.766422 0.533557 … -0.794117 -0.429164; 1.11019 -0.34358 … -0.37434 0.944343],\n",
       "\n",
       "Float32[0.711309 0.888573 … 0.230551 0.995183; 0.953154 0.81466 … 0.0788147 0.430766; 0.863309 0.144928 … 0.958333 0.595142; 0.545098 0.541176 … 0.376471 0.968627]))"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x_train, y_train), (x_test, y_test) = get_data(test_training_dict)\n",
    "M = fit(ICA, collect(x_train), 10)#; maxoutdim=100)\n",
    "\n",
    "\n",
    "\n",
    "x_train_dr = MultivariateStats.transform(M,x_train)\n",
    "x_test_dr =  MultivariateStats.transform(M,x_test)\n",
    "(train,test) = (x_train_dr, y_train), (x_test_dr, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Method definition my_test_loss(Any, Any) in module Main at In[9]:2 overwritten at In[31]:2.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "StochasticOptimization.IterFunction(#9)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function my_test_loss(obj, testdata)\n",
    "    totloss = 0.0\n",
    "    totcorrect = 0\n",
    "    for (x,y) in eachobs(testdata)\n",
    "        totloss += transform!(obj,y,x)\n",
    "    end\n",
    "    totloss#, totcorrect/totcount\n",
    "end\n",
    "\n",
    "\n",
    "tracer = IterFunction() do obj, i\n",
    "    if mod1(i,1000)==1000\n",
    "        totloss  = my_test_loss(obj, test)\n",
    "        println(i, \" totloss:  \", totloss)\n",
    "        #println(i, \" accuracy: \", accuracy)\n",
    "    end\n",
    "end\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}(Chain{Float64}(\n",
       "   Affine{10-->100}\n",
       "   softplus{100}\n",
       "   Affine{100-->50}\n",
       "   softplus{50}\n",
       "   Affine{50-->4}\n",
       "   logistic{4}\n",
       ") ,ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss}(LossFunctions.CrossentropyLoss(),4,input(4,),target(4,),output(1,)),Penalties.ElasticNetPenalty{Float64}(1.0e-5,0.5))"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nin, nh, nout = size(train[1],1), [100,50], size(train[2],1)\n",
    "t = nnet(nin, nout, nh, :softplus, :logistic)\n",
    "obj = objective(t, ElasticNetPenalty(1e-5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000 totloss:  307.2286445247243\n",
      "2000 totloss:  302.4062560267238\n",
      "3000 totloss:  300.62796138139254\n",
      "4000 totloss:  299.94444006055863\n",
      "5000 totloss:  297.26565633344495\n",
      "6000 totloss:  297.5546861622681\n"
     ]
    },
    {
     "ename": "LoadError",
     "evalue": "InterruptException:",
     "output_type": "error",
     "traceback": [
      "InterruptException:",
      "",
      " in mapfoldl_impl(::Base.#identity, ::Base.#+, ::Float64, ::Base.Generator{UnitRange{Int64},Transformations.##6#7{Base.ReshapedArray{Float64,2,SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{}}}}, ::Int64) at ./reduce.jl:48",
      " in mapfoldl(::Base.#identity, ::Function, ::Base.Generator{UnitRange{Int64},Transformations.##6#7{Base.ReshapedArray{Float64,2,SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{}}}}) at ./reduce.jl:64",
      " in transform!(::Transformations.Affine{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{Base.ReshapedArray{Float64,2,SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{}},SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}},Tuple{Tuple{Int64,Int64},Tuple{Int64}}}}) at /home/ubuntu/.julia/v0.5/Transformations/src/affine.jl:39",
      " in foreach(::LearnBase.#transform!, ::Array{LearnBase.Transformation,1}) at ./abstractarray.jl:1553",
      " in transform! at /home/ubuntu/.julia/v0.5/Transformations/src/chain.jl:75 [inlined]",
      " in transform! at /home/ubuntu/.julia/v0.5/Transformations/src/Transformations.jl:98 [inlined]",
      " in transform!(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::SubArray{Float32,1,Array{Float32,2},Tuple{Colon,Int64},true}, ::SubArray{Float64,1,Array{Float64,2},Tuple{Colon,Int64},true}) at /home/ubuntu/.julia/v0.5/ObjectiveFunctions/src/ObjectiveFunctions.jl:152",
      " in update!(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::Tuple{SubArray{Float64,1,Array{Float64,2},Tuple{Colon,Int64},true},SubArray{Float32,1,Array{Float32,2},Tuple{Colon,Int64},true}}) at /home/ubuntu/.julia/v0.5/Transformations/src/Transformations.jl:117",
      " in search_direction(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::StochasticOptimization.GradientAverager, ::StochasticOptimization.DataSubset{Tuple{Array{Float64,2},Array{Float32,2}},Array{Int64,1}}) at /home/ubuntu/.julia/v0.5/StochasticOptimization/src/strategies.jl:251",
      " in learn!(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::StochasticOptimization.GradientLearner{StochasticOptimization.FixedLR,StochasticOptimization.Adadelta{Float64},StochasticOptimization.GradientAverager}, ::StochasticOptimization.DataSubset{Tuple{Array{Float64,2},Array{Float32,2}},Array{Int64,1}}) at /home/ubuntu/.julia/v0.5/StochasticOptimization/src/strategies.jl:305",
      " in learn!(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::StochasticOptimization.MetaLearner{Tuple{StochasticOptimization.GradientLearner{StochasticOptimization.FixedLR,StochasticOptimization.Adadelta{Float64},StochasticOptimization.GradientAverager},StochasticOptimization.IterFunction,StochasticOptimization.MaxIter}}, ::Iterators.RepeatCallForever) at /home/ubuntu/.julia/v0.5/StochasticOptimization/src/strategies.jl:36"
     ]
    }
   ],
   "source": [
    "learner = make_learner(\n",
    "    GradientLearner(5e-2, Adadelta()),\n",
    "    tracer,\n",
    "    maxiter = 50_000\n",
    ")\n",
    "learn!(obj, learner, infinite_batches(train, size=5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "full_encode_input(M,\"hyperblue\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Method definition get_colour(Any, Any, Any) in module Main at In[34]:2 overwritten at In[38]:2.\n",
      "WARNING: Method definition get_colour(Any) in module Main at In[34]:5 overwritten at In[38]:5.\n",
      "WARNING: Method definition display_colour(Any, Any, Any) in module Main at In[34]:9 overwritten at In[38]:9.\n",
      "WARNING: Method definition display_colour(Any) in module Main at In[34]:13 overwritten at In[38]:13.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "display_colour (generic function with 2 methods)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function get_colour(obj, M, name)\n",
    "    x = full_encode_input(M,name)\n",
    "    decode_output( output_value(obj.transformation ))\n",
    "end\n",
    "get_colour(name) = get_colour(obj, M, name)\n",
    "\n",
    "\n",
    "function display_colour(obj, M,name)\n",
    "    display(name)\n",
    "    display(get_colour(obj, M, name))\n",
    "    display(\"-\"^16)\n",
    "end\n",
    "display_colour(name)=display_colour(obj, M,name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"green\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"red\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"lightred\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"dirtyred\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"lightredishblue\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"bluish red\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"blue\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"light blue\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"lightred\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_colour(\"green\")\n",
    "display_colour(\"red\")\n",
    "display_colour(\"lightred\")\n",
    "display_colour(\"dirtyred\")\n",
    "display_colour(\"lightredishblue\")\n",
    "display_colour(\"bluish red\")\n",
    "display_colour(\"blue\")\n",
    "display_colour(\"light blue\")\n",
    "display_colour(\"lightred\")\n",
    " \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"hot pink\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"hot blue\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"hot green\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"dark blue\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"light black\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"black\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"dark black\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
       "     width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
       "     <rect width=\"1\" height=\"1\"\n",
       "           fill=\"#1FC42B\" stroke=\"none\"/>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "HSV{Float64}(124.54287639257743,0.8442465300052067,0.7689936138559682)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\"----------------\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_colour(\"hot pink\")\n",
    "display_colour(\"hot blue\")\n",
    "display_colour(\"hot green\")\n",
    "display_colour(\"dark blue\")\n",
    "display_colour(\"light black\")\n",
    "display_colour(\"black\")\n",
    "display_colour(\"dark black\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "MethodError: no method matching display_colour(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::String)\u001b[0m\nClosest candidates are:\n  display_colour(::Any, ::Any, \u001b[1m\u001b[31m::Any\u001b[0m) at In[38]:9\n  display_colour(::Any) at In[38]:13\u001b[0m",
     "output_type": "error",
     "traceback": [
      "MethodError: no method matching display_colour(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::String)\u001b[0m\nClosest candidates are:\n  display_colour(::Any, ::Any, \u001b[1m\u001b[31m::Any\u001b[0m) at In[38]:9\n  display_colour(::Any) at In[38]:13\u001b[0m",
      "",
      " in macro expansion; at ./In[41]:2 [inlined]",
      " in anonymous at ./<missing>:?"
     ]
    }
   ],
   "source": [
    "for letter in ['a':'z'; ' '; '\\''; '/']\n",
    "    display_colour(obj, string(letter))\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "MethodError: no method matching display_colour(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::String)\u001b[0m\nClosest candidates are:\n  display_colour(::Any, ::Any, \u001b[1m\u001b[31m::Any\u001b[0m) at In[19]:9\n  display_colour(::Any) at In[19]:13\u001b[0m",
     "output_type": "error",
     "traceback": [
      "MethodError: no method matching display_colour(::ObjectiveFunctions.RegularizedObjective{Transformations.Chain{Float64,Transformations.Params{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{},Tuple{}}},ObjectiveFunctions.LossTransform{Float64,LossFunctions.CrossentropyLoss},Penalties.ElasticNetPenalty{Float64}}, ::String)\u001b[0m\nClosest candidates are:\n  display_colour(::Any, ::Any, \u001b[1m\u001b[31m::Any\u001b[0m) at In[19]:9\n  display_colour(::Any) at In[19]:13\u001b[0m",
      "",
      " in macro expansion; at ./In[24]:3 [inlined]",
      " in anonymous at ./<missing>:?"
     ]
    }
   ],
   "source": [
    "for letter1 in ['a':'z'; ' '; '\\''; '/']\n",
    "    for letter2 in ['a':'z'; ' '; '\\''; '/']\n",
    "        display_colour(obj, join([letter1,letter2]))\n",
    "    end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "1+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.5.0",
   "language": "julia",
   "name": "julia-0.5"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.5.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
